package com.srit.yoggsaron.common;


import java.util.ArrayList;
import java.util.List;

public final class JsonQuery {
	private List<Condition> conditions;
	private Relation relation;
	private List<OrderBy> orderBy;
	private long start =0L;
	private int limit=200;
	private int all;
	
	public int getAll() {
		return all;
	}

	public void setAll(int all) {
		this.all = all;
	}

	public List<Condition> getConditions() {
		if (conditions == null) {
			conditions = new ArrayList<Condition>();
		}
		return conditions;
	}

	public void setConditions(List<Condition> conditions) {
		this.conditions = conditions;
	}

	public Relation getRelation() {
		if (relation == null) {
			relation = Relation.AND;
		}
		return relation;
	}

	public void setRelation(Relation relation) {
		this.relation = relation;
	}

	public List<OrderBy> getOrderBy() {
		if (orderBy == null) {
			orderBy = new ArrayList<OrderBy>();
		}
		return orderBy;
	}

	public void setOrderBy(List<OrderBy> orderBy) {
		this.orderBy = orderBy;
	}

	public long getStart() {
		return start;
	}

	public void setStart(long start) {
		this.start = start;
	}

	public int getLimit() {
		return limit;
	}

	public void setLimit(int limit) {
		this.limit = limit;
	}

	public enum OrderSequence {
		ASC, DESC
	}

	public enum Relation {
		AND, OR
	}

	public static class OrderBy {
		private String name;
		private OrderSequence order;

		public OrderBy(String name , OrderSequence order )
		{
			this.name=name;
			this.order=order;
		}
		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public OrderSequence getOrder() {
			if (order == null) {
				order = OrderSequence.ASC;
			}
			return order;
		}

		public void setOrder(OrderSequence order) {
			this.order = order;
		}
	}

	public static class Condition {
		private String name; // 数据库字段名称，可以带表别名，如r.rolename
		private String value; // 匹配
		private String logic="="; // 枚举：[=,>,>=,<,<=,<>,LIKE,BETWEEN,IN,SQL]
		private String value2; // 当logic=BETWEEN时，后面那个值
		private List<String> values; // 当logic=IN时，后面那个值
		private String relation="AND"; // 当使用SQL拼接时，此值需置为字段的前置关系：AND OR

		public Condition() {
		}

		public Condition(String name, String logic, String value) {
			super();
			this.name = name;
			this.value = value;
			this.logic = logic;
		}

		public String getName() {
			return name;
		}

		public void setName(String name) {
			this.name = name;
		}

		public String getValue() {
			return value;
		}

		public void setValue(String value) {
			this.value = value;
		}

		public String getLogic() {
			return logic;
		}

		public void setLogic(String logic) {
			this.logic = logic;
		}

		public String getValue2() {
			return value2;
		}

		public void setValue2(String value2) {
			this.value2 = value2;
		}

		public void setValues(List<String> values) {
			this.values = values;
		}

		public List<String> getValues() {
			return values;
		}

		public String getRelation() {
			return relation;
		}

		public void setRelation(String relation) {
			this.relation = relation;
		}
	}
}
